/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package com.carpark.ejb.Model;

import java.io.Serializable;
import java.util.Date;
import javax.persistence.Basic;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.NamedQueries;
import javax.persistence.NamedQuery;
import javax.persistence.Table;
import javax.persistence.Temporal;
import javax.persistence.TemporalType;
import javax.validation.constraints.NotNull;
import javax.validation.constraints.Size;
import javax.xml.bind.annotation.XmlRootElement;

/**
 *
 * @author Krzysztof
 */
@Entity
@Table(name = "payments")
@XmlRootElement
@NamedQueries({
    @NamedQuery(name = "PaymentsModel.findAll", query = "SELECT p FROM PaymentsModel p"),
    @NamedQuery(name = "PaymentsModel.findByPaymentId", query = "SELECT p FROM PaymentsModel p WHERE p.paymentId = :paymentId"),
    @NamedQuery(name = "PaymentsModel.findByClientId", query = "SELECT bm FROM PaymentsModel bm INNER JOIN  bm.receivableId s INNER JOIN s.parkingPassId d INNER JOIN d.passesrecordsModelCollection g WHERE g.clientId = :clientId"),
    @NamedQuery(name = "PaymentsModel.findByPaymentDate", query = "SELECT p FROM PaymentsModel p WHERE p.paymentDate = :paymentDate"),
     @NamedQuery(name = "PaymentsModel.findPayedReceivables", query = "SELECT p.receivableId FROM PaymentsModel p INNER JOIN p.receivableId  s WHERE s.receivableId = p.receivableId"),
    @NamedQuery(name = "PaymentsModel.findByPaymentForm", query = "SELECT p FROM PaymentsModel p WHERE p.paymentForm = :paymentForm")})
public class PaymentsModel implements Serializable {
    private static final long serialVersionUID = 1L;
    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    @Basic(optional = false)
    @Column(name = "PaymentId")
    private Integer paymentId;
    @Basic(optional = false)
    @NotNull
    @Column(name = "PaymentDate")
    @Temporal(TemporalType.TIMESTAMP)
    private Date paymentDate;
    @Basic(optional = false)
    @NotNull
    @Size(min = 1, max = 10)
    @Column(name = "PaymentForm")
    private String paymentForm;
    @JoinColumn(name = "ReceivableId", referencedColumnName = "ReceivableId")
    @ManyToOne(optional = false)
    private ReceivablesModel receivableId;

    public PaymentsModel() {
    }

    public PaymentsModel(Integer paymentId) {
        this.paymentId = paymentId;
    }

    public PaymentsModel(Integer paymentId, Date paymentDate, String paymentForm) {
        this.paymentId = paymentId;
        this.paymentDate = paymentDate;
        this.paymentForm = paymentForm;
    }
    
    public PaymentsModel(Date paymentDate, String paymentForm) {
        this.paymentDate = paymentDate;
        this.paymentForm = paymentForm;
    }

    public Integer getPaymentId() {
        return paymentId;
    }

    public void setPaymentId(Integer paymentId) {
        this.paymentId = paymentId;
    }

    public Date getPaymentDate() {
        return paymentDate;
    }

    public void setPaymentDate(Date paymentDate) {
        this.paymentDate = paymentDate;
    }

    public String getPaymentForm() {
        return paymentForm;
    }

    public void setPaymentForm(String paymentForm) {
        this.paymentForm = paymentForm;
    }

    public ReceivablesModel getReceivableId() {
        return receivableId;
    }

    public void setReceivableId(ReceivablesModel receivableId) {
        this.receivableId = receivableId;
    }

    

    @Override
    public boolean equals(Object object) {
        // TODO: Warning - this method won't work in the case the id fields are not set
        if (!(object instanceof PaymentsModel)) {
            return false;
        }
        PaymentsModel other = (PaymentsModel) object;
        if ((this.paymentId == null && other.paymentId != null) || (this.paymentId != null && !this.paymentId.equals(other.paymentId))) {
            return false;
        }
        return true;
    }

    @Override
    public String toString() {
        return "com.carpark.ejb.Model.PaymentsModel[ paymentId=" + paymentId + " ]";
    }
    
}
